package com.aaa.controller;

import com.aaa.entity.Back_User;
import com.aaa.entity.Foul;
import com.aaa.entity.Menu;
import com.aaa.service.impl.FoulServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: MenuController
 * @Description: TODO
 * @Author: 86139
 * @Date: 2021/9/3 22:41
 * @Version:1.0
 **/
@Api(tags = "犯规类型管理")
@RestController
@CrossOrigin
@RequestMapping("foul")
public class FoulController {
    @Autowired
    FoulServiceImpl foulService;
    @ApiOperation("查询所有犯规类型")
    @RequestMapping("finAll")
    public PageInfo<Map<String, Object>> SelectAll(Integer pageNum, Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Map<String,Object>> list = foulService.listMaps();
        PageInfo<Map<String,Object>> rolePageInfo = new PageInfo(list);
        return rolePageInfo;
    }
    @RequestMapping("add")
    public boolean add(Foul foul){
//        List<Map<String,Object>> list = foulService.addAfter(foul.getFid());
        QueryWrapper<Foul> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.eq("fname",foul.getFname());
        List<Map<String, Object>> list1 = foulService.listMaps(objectQueryWrapper);
        if(list1.size()>0){
            return false;
        }
        foul.setState("0");
        return foulService.save(foul);
    }
    @RequestMapping("update")
    public boolean update(Foul foul){
        System.out.println(foul);
        QueryWrapper<Foul> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.eq("fname",foul.getFname());
        List<Map<String,Object>> list = foulService.listMaps(objectQueryWrapper);
        System.out.println(list);
        if(list.size()>0){
            QueryWrapper<Foul> wrapper = new QueryWrapper<>();
            objectQueryWrapper.eq("fid",foul.getFid());
            Map<String,Object> list1 = foulService.listMaps(wrapper).get(0);
            if(list1.get("fname").equals(foul.getFname())){
                return foulService.updateById(foul);
            }
            return false;
        }else {
            return foulService.updateById(foul);
        }
    }
    @RequestMapping("state")
    public boolean state(Foul foul){
        return foulService.updateById(foul);
    }

}
